% A = GF_ADD_ONE(V)   Build an add-one table for the GF with vector space
% stored in v.
%
%  Input
%         v   The vector space of the Galois Field for which the add-one
%             table is to be constructed.
%
%  Output
%         A   Add-one table for this Galois Field. Format:
%
%             log_a(a^q)   log_a(a^q + 1)
%
%             An entry of -1 indicates a value for which the log is not
%             defined (denoted as a * in the text).

function A = gf_add_one(v)

    % Init add-one table
    A = zeros(size(v,1),2);
    
    % Process each row in the table
    for i = 1:size(v,1)-2
       A(i,1) = i;
       t = v(i,:);
       t(1) = xor(1,t(1));  % "add one"
       for j = 1:size(v,1)  % Match to entry in "add-one" matrix 
          if v(j,:) == t
             A(i,2) = j; 
          end
       end
    end
    
    % Set the zero logs
    A(end-1,1) = 0;
    A(end-1,2) = -1;
    A(end,1)   = -1;
    A(end,2)   = 0;

end
